package com.example.musicaiap.ui.player

import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import com.example.musicaiap.domain.model.Song
import com.example.musicaiap.mvi.base.UiEffect
import com.example.musicaiap.mvi.base.UiIntent
import com.example.musicaiap.mvi.base.UiState

/**
 * 播放器MVI契约
 */
object PlayerContract {
    /**
     * 播放模式枚举
     */
    enum class PlayMode {
        SEQUENCE,    // 顺序播放
        SHUFFLE,     // 随机播放
        REPEAT_ONE,  // 单曲循环
        REPEAT_ALL   // 列表循环
    }

    /**
     * 播放器状态
     */
    data class PlayerState(
        val currentSong: Song? = null,
        val currentMediaItem: MediaItem? = null,
        val playbackState: Int = Player.STATE_IDLE,
        val isPlaying: Boolean = false,
        val currentPosition: Long = 0,
        val duration: Long = 0,
        val playbackSpeed: Float = 1.0f,
        val repeatMode: Int = Player.REPEAT_MODE_OFF,
        val shuffleModeEnabled: Boolean = false,
        val isFavorite: Boolean = false,
        val error: String? = null,
        val playMode: PlayMode = PlayMode.SEQUENCE,
        val currentPlaylist: List<Song> = emptyList()
    ) : UiState
    
    /**
     * 播放器意图
     */
    sealed interface PlayerIntent : UiIntent {
        data class PlaySong(val song: Song) : PlayerIntent
        data class PlaySongs(val songs: List<Song>, val startIndex: Int = 0) : PlayerIntent
        object PlayPause : PlayerIntent
        object SkipNext : PlayerIntent
        object SkipPrevious : PlayerIntent
        data class SeekTo(val positionMs: Long) : PlayerIntent
        data class SetPlaybackSpeed(val speed: Float) : PlayerIntent
        data class SetRepeatMode(val repeatMode: Int) : PlayerIntent
        data class SetShuffleMode(val enabled: Boolean) : PlayerIntent
        data class ToggleFavorite(val songId: String) : PlayerIntent
        object TogglePlayMode : PlayerIntent
    }
    
    /**
     * 播放器副作用
     */
    sealed interface PlayerEffect : UiEffect {
        data class PlaybackError(val message: String) : PlayerEffect
        data class MediaItemTransition(val song: Song?) : PlayerEffect
        object PlaybackCompleted : PlayerEffect
        data class FavoriteChanged(val isFavorite: Boolean) : PlayerEffect
        data class PlayModeChanged(val mode: PlayMode) : PlayerEffect
    }
} 